package com.tangkun.environment.fragment.main;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tangkun.environment.R;
import com.tangkun.environment.activity.TiJianActivity;
import com.tangkun.environment.application.Session;
import com.tangkun.environment.entity.gongzuo.PatientsReturn;
import com.tangkun.environment.entity.shouye.IndexIndexReturn;
import com.tangkun.environment.fragment.BaseFragment;
import com.tangkun.environment.network.GlobalUrl;
import com.tangkun.environment.network.MySubscribe;
import com.tangkun.environment.rx.RxFragmentHelper;
import com.tangkun.environment.utils.JumpHelper;
import com.tangkun.environment.utils.LogUtils;
import com.tangkun.environment.utils.SharePrefercesUtils;
import com.tangkun.environment.view.CircleImageView;
import com.tangkun.environment.view.CircleProgress;

import org.simple.eventbus.EventBus;
import org.simple.eventbus.Subscriber;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
import zxing.activity.MipcaCaptureActivity;

/**
 * 首页
 */

public class Main1Fragment extends BaseFragment {

    @BindView(R.id.civ_main_photo)
    CircleImageView civMainPhoto;
    @BindView(R.id.iv_main1_logo)
    ImageView ivMain1Logo;
    @BindView(R.id.tv_main1_logo)
    TextView tvMain1Logo;
    @BindView(R.id.ll_main1_bg)
    LinearLayout llMain1Bg;
    @BindView(R.id.iv_main1_jichushuju)
    ImageView ivMain1Jichushuju;
    @BindView(R.id.tv_main1_jichushuju)
    TextView tvMain1Jichushuju;
    @BindView(R.id.ll_main1_jichushuju)
    LinearLayout llMain1Jichushuju;
    @BindView(R.id.iv_main1_xunchashuju)
    ImageView ivMain1Xunchashuju;
    @BindView(R.id.tv_main1_xunchashuju)
    TextView tvMain1Xunchashuju;
    @BindView(R.id.ll_main1_xunchashuju)
    LinearLayout llMain1Xunchashuju;
    @BindView(R.id.iv_main1_yichangjubao)
    ImageView ivMain1Yichangjubao;
    @BindView(R.id.tv_main1_yichangjubao)
    TextView tvMain1Yichangjubao;
    @BindView(R.id.ll_main1_yichangjubao)
    LinearLayout llMain1Yichangjubao;
    @BindView(R.id.iv_main1_jichushuju_right)
    ImageView ivMain1JichushujuRight;
    @BindView(R.id.iv_main1_xunchashuju_right)
    ImageView ivMain1XunchashujuRight;
    @BindView(R.id.iv_main1_yichangjubao_right)
    ImageView ivMain1YichangjubaoRight;
    @BindView(R.id.circleprogress)
    CircleProgress circleprogress;

    /**
     * 数据源
     */
    private List<PatientsReturn.Patients.ItemsBean> dataList = new ArrayList<PatientsReturn.Patients.ItemsBean>();

    /**
     * 0未登录 1登录但未绑定 2检测到有污染数据异常 3协会巡查员
     */
    private int status = 0;

    /**
     * 进度条渐变色
     */
    private final static int[] gradientColorsGreen = new int[]{Color.parseColor("#009961"), Color.parseColor("#009961"), Color.parseColor("#009961")};
    private final static int[] gradientColorsYellow = new int[]{Color.parseColor("#F3B247"), Color.parseColor("#F3B247"), Color.parseColor("#F3B247")};
    private final static int[] gradientColorsRed = new int[]{Color.parseColor("#ED5930"), Color.parseColor("#ED5930"), Color.parseColor("#ED5930")};

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.fragment_main1, container, false);
        ButterKnife.bind(this, view);
        EventBus.getDefault().register(this);
        updateUiByStatus(null);
        indexIndex();
        initData();
        return view;
    }

    private void initData() {
        //顶部左上角头像
        Glide.with(getActivity())
                .load(GlobalUrl.IMG_URL + Session.getInstance().getUserHeadPicture())
                .bitmapTransform(new CropCircleTransformation(getActivity()))
                .placeholder(R.mipmap.ic_wrong_head)
                .dontAnimate()
                .into(civMainPhoto);

    }

    @Override
    public void onResume() {
        super.onResume();
        initData();
    }

    /**
     * 首页数据
     */
    private void indexIndex() {
        //已登录并且已绑定
        if (SharePrefercesUtils.getLoginStatus(getActivity()) && SharePrefercesUtils.getBindStatus(getActivity())) {
            fromNetwork.indexIndex().compose(new RxFragmentHelper<IndexIndexReturn>().ioMain(getActivity(), Main1Fragment.this, true))
                    .subscribe(new MySubscribe<IndexIndexReturn>(getActivity(), true) {
                        @Override
                        protected void success(IndexIndexReturn resultBean) {
                            if (resultBean.data != null) {
                                updateUiByStatus(resultBean.data);
                            }
                        }

                        @Override
                        protected void onMyError(String errorMessage) {
                            showToast(errorMessage);
                        }
                    });
            if (Session.getInstance().getUserRole().equals("企业用户")) {

            } else if (Session.getInstance().getUserRole().equals("街道巡查员")) {

            } else if (Session.getInstance().getUserRole().equals("协会巡查员")) {

            } else if (Session.getInstance().getUserRole().equals("监督员")) {

            }
        }
    }

    /**
     * 根据当前身份更新UI
     * status 0未登录 1登录但未绑定 2检测到有污染数据异常 3协会巡查员
     *
     * @param dataBean 首页返回数据集合
     */
    private void updateUiByStatus(IndexIndexReturn.DataBean dataBean) {
        if (!SharePrefercesUtils.getLoginStatus(getActivity())) {
            //未登录
            status = 0;
            ivMain1Logo.setImageResource(R.mipmap.ic_shield_green);
            tvMain1Logo.setText("登录环保管家");
            llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_green);
            ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_green);
            ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_green);
            ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_green);
            tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_tips));
            tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_tips));
            tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_tips));
            tvMain1Jichushuju.setText("基础环保数据，修改、异常及时知晓");
            tvMain1Xunchashuju.setText("主动提交巡查数据，助力巡查提速");
            tvMain1Yichangjubao.setText("污染源异常全知道");
            ivMain1JichushujuRight.setVisibility(View.GONE);
            ivMain1XunchashujuRight.setVisibility(View.GONE);
            ivMain1YichangjubaoRight.setVisibility(View.GONE);
            llMain1Jichushuju.setEnabled(false);
            llMain1Xunchashuju.setEnabled(false);
            llMain1Yichangjubao.setEnabled(false);
        } else {
            //已登录
            if (!SharePrefercesUtils.getBindStatus(getActivity())) {
                //登录未绑定
                status = 1;
                ivMain1Logo.setImageResource(R.mipmap.ic_shield_green);
                circleprogress.setVisibility(View.GONE);
                tvMain1Logo.setText("");
                llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_green);
                ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_green);
                ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_green);
                ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_green);
                tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_tips));
                tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_tips));
                tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_tips));
                tvMain1Logo.setText("关联企业，体验环保管家");
                tvMain1Jichushuju.setText("基础环保数据，修改、异常及时知晓");
                tvMain1Xunchashuju.setText("主动提交巡查数据，助力巡查提速");
                tvMain1Yichangjubao.setText("污染源异常全知道");
                ivMain1JichushujuRight.setVisibility(View.GONE);
                ivMain1XunchashujuRight.setVisibility(View.GONE);
                ivMain1YichangjubaoRight.setVisibility(View.GONE);
                llMain1Jichushuju.setEnabled(false);
                llMain1Xunchashuju.setEnabled(false);
                llMain1Yichangjubao.setEnabled(false);
            } else {
                //登录已绑定
                if (dataBean == null) {
                    return;
                }

                if (Session.getInstance().getUserRole().equals("企业用户")) {
                    if (dataBean.basicErrorNum == 0 && dataBean.inspectErrorNum == 0 && dataBean.reportNum == 0) {
                        //没有错误数据
                        ivMain1Logo.setImageResource(R.mipmap.ic_shield_green);
                        circleprogress.setVisibility(View.GONE);
                        tvMain1Logo.setText("未检测到污染数据异常");
                        llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_green);
                        ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_green);
                        ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_green);
                        ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_green);
                        tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_tips));
                        tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_tips));
                        tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_tips));
                        ivMain1JichushujuRight.setVisibility(View.GONE);
                        ivMain1XunchashujuRight.setVisibility(View.GONE);
                        ivMain1YichangjubaoRight.setVisibility(View.GONE);
                        llMain1Jichushuju.setEnabled(false);
                        llMain1Xunchashuju.setEnabled(false);
                        llMain1Yichangjubao.setEnabled(false);
                    } else if (dataBean.basicErrorNum != 0 && dataBean.inspectErrorNum != 0 && dataBean.reportNum != 0) {
                        //全部都有错误数据
                        tvMain1Logo.setText("检测到有污染数据异常");
                        ivMain1Logo.setImageResource(R.mipmap.ic_shield_red);
                        llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_red);
                        ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_red);
                        ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_red);
                        ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_red);
                        tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_red));
                        tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_red));
                        tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_red));
                        ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                        ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                        ivMain1YichangjubaoRight.setVisibility(View.VISIBLE);
                        llMain1Jichushuju.setEnabled(true);
                        llMain1Xunchashuju.setEnabled(true);
                        llMain1Yichangjubao.setEnabled(true);
                    } else {
                        //包含错误，但不是全部错误
                        tvMain1Logo.setText("检测到有污染数据异常");
                        ivMain1Logo.setImageResource(R.mipmap.ic_shield_yellow);
                        llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_orange);
                        ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_orange);
                        ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_orange);
                        ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_orange);
                        //基础数据
                        if (dataBean.basicErrorNum == 0) {
                            tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_tips));
                            ivMain1JichushujuRight.setVisibility(View.GONE);
                            llMain1Jichushuju.setEnabled(false);
                        } else {
                            tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_orange));
                            ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                            llMain1Jichushuju.setEnabled(true);
                        }
                        //巡查数据文案
                        if (dataBean.inspectErrorNum == 0) {
                            tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_tips));
                            ivMain1XunchashujuRight.setVisibility(View.GONE);
                            llMain1Xunchashuju.setEnabled(false);
                        } else {
                            tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_orange));
                            ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                            llMain1Xunchashuju.setEnabled(true);
                        }
                        //异常举报文案
                        if (dataBean.reportNum == 0) {
                            tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_tips));
                            ivMain1YichangjubaoRight.setVisibility(View.GONE);
                            llMain1Yichangjubao.setEnabled(false);
                        } else {
                            tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_orange));
                            ivMain1YichangjubaoRight.setVisibility(View.VISIBLE);
                            llMain1Yichangjubao.setEnabled(true);
                        }
                    }

                    circleprogress.setVisibility(View.GONE);
                    //logo下面文案
                    if (dataBean.basicErrorNum == 0 && dataBean.inspectErrorNum == 0 && dataBean.reportNum == 0) {
                        //没有错误数据
                        tvMain1Logo.setText("未检测到污染数据异常");
                    } else if (dataBean.basicErrorNum != 0 && dataBean.inspectErrorNum != 0 && dataBean.reportNum != 0) {
                        //全部都有错误数据
                        tvMain1Logo.setText("检测到有污染数据异常");
                    } else {
                        //包含错误，但不是全部错误
                        tvMain1Logo.setText("检测到有污染数据异常");
                    }

                    //基础数据文案
                    if (dataBean.basicErrorNum == 0) {
                        tvMain1Jichushuju.setText("全部基础数据正常");
                    } else {
                        tvMain1Jichushuju.setText("已绑" + dataBean.basicBindNum + "家企业，缺少" + dataBean.basicErrorNum + "组数据");
                    }
                    //巡查数据文案
                    if (dataBean.inspectErrorNum == 0) {
                        tvMain1Xunchashuju.setText("全部巡查数据正常");
                    } else {
                        tvMain1Xunchashuju.setText("已绑" + dataBean.inspectBindNum + "家企业，缺少" + dataBean.inspectErrorNum + "组数据");
                    }
                    //异常举报文案
                    if (dataBean.reportNum == 0 && dataBean.reportEpNum == 0) {
                        tvMain1Yichangjubao.setText("无企业被举报");
                    } else {
                        tvMain1Yichangjubao.setText(dataBean.reportEpNum + "家企业被举报" + dataBean.reportNum + "次，已全部处理");
                    }

                    ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                    ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                    ivMain1YichangjubaoRight.setVisibility(View.INVISIBLE);
                    llMain1Jichushuju.setEnabled(true);
                    llMain1Xunchashuju.setEnabled(true);
                    llMain1Yichangjubao.setEnabled(false);
                } else if (Session.getInstance().getUserRole().equals("街道巡查员")) {
//                    "finishRate":1.0,
//                    "remainNum":0,
//                    "reportNum":4,
//                    "inspectAuditNum":0,
//                    "inspectErrorNum":0
//                    当月的计划工作已全部完成
//                    当月工作已完成xx %，剩余xxx污染源
                    circleprogress.setVisibility(View.VISIBLE);
                    circleprogress.reset();
                    circleprogress.clearAnimation();//清除动画试试
                    circleprogress.setValue(dataBean.finishRate * 100); //值
                    //logo下文案
                    if (dataBean.finishRate == 1) {
                        //已完成
                        tvMain1Logo.setText("当月的计划工作已全部完成");
                    } else {
                        tvMain1Logo.setText("当月工作已完成" + dataBean.finishRate * 100 + "%\n剩余" + dataBean.remainNum + "污染源待处理");
                    }

                    if (dataBean.basicErrorNum == 0 && dataBean.inspectErrorNum == 0 && dataBean.reportNum == 0) {
                        //没有错误数据
                        circleprogress.setGradientColors(gradientColorsGreen);
                        ivMain1Logo.setImageResource(R.mipmap.ic_shield_green);
                        llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_green);
                        ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_green);
                        ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_green);
                        ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_green);
                        tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_tips));
                        tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_tips));
                        tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_tips));
                        ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                        ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                        ivMain1YichangjubaoRight.setVisibility(View.VISIBLE);
                        llMain1Jichushuju.setEnabled(true);
                        llMain1Xunchashuju.setEnabled(true);
                        llMain1Yichangjubao.setEnabled(true);
                    } else if (dataBean.basicErrorNum != 0 && dataBean.inspectErrorNum != 0 && dataBean.reportNum != 0) {
                        //全部都有错误数据
                        circleprogress.setGradientColors(gradientColorsRed);
                        ivMain1Logo.setImageResource(R.mipmap.ic_shield_red);
                        llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_red);
                        ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_red);
                        ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_red);
                        ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_red);
                        tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_red));
                        tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_red));
                        tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_red));
                        ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                        ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                        ivMain1YichangjubaoRight.setVisibility(View.VISIBLE);
                        llMain1Jichushuju.setEnabled(true);
                        llMain1Xunchashuju.setEnabled(true);
                        llMain1Yichangjubao.setEnabled(true);
                    } else {
                        //包含错误，但不是全部错误
                        //logo和下面文案
                        circleprogress.setGradientColors(gradientColorsYellow);
                        ivMain1Logo.setImageResource(R.mipmap.ic_shield_yellow);
                        llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_orange);
                        ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_orange);
                        ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_orange);
                        ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_orange);
                        //基础数据
                        if (dataBean.basicErrorNum == 0) {
                            tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_tips));
                            ivMain1JichushujuRight.setVisibility(View.GONE);
                            llMain1Jichushuju.setEnabled(false);
                        } else {
                            tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_orange));
                            ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                            llMain1Jichushuju.setEnabled(true);
                        }
                        //巡查数据文案
                        if (dataBean.inspectErrorNum == 0) {
                            tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_tips));
                            ivMain1XunchashujuRight.setVisibility(View.GONE);
                            llMain1Xunchashuju.setEnabled(false);
                        } else {
                            tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_orange));
                            ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                            llMain1Xunchashuju.setEnabled(true);
                        }
                        //异常举报文案
                        if (dataBean.reportNum == 0) {
                            tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_tips));
                            ivMain1YichangjubaoRight.setVisibility(View.GONE);
                            llMain1Yichangjubao.setEnabled(false);
                        } else {
                            tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_orange));
                            ivMain1YichangjubaoRight.setVisibility(View.VISIBLE);
                            llMain1Yichangjubao.setEnabled(true);
                        }
                    }

                    //基础数据文案
                    tvMain1Jichushuju.setText("待审核" + dataBean.basicAuditNum + "家污染源，其中异常" + dataBean.basicErrorNum + "家");
                    //巡查数据文案
                    tvMain1Xunchashuju.setText("待审核" + dataBean.inspectAuditNum + "家污染源，其中异常" + dataBean.inspectErrorNum + "家");
                    //异常举报文案
                    tvMain1Yichangjubao.setText(dataBean.reportNum + "家污染源举报数据待处理");

                    ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                    ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                    ivMain1YichangjubaoRight.setVisibility(View.VISIBLE);
                    llMain1Jichushuju.setEnabled(true);
                    llMain1Xunchashuju.setEnabled(true);
                    llMain1Yichangjubao.setEnabled(true);
                } else if (Session.getInstance().getUserRole().equals("协会巡查员")) {
                   /* "reportNum": 3,
                    "finishRate": 1.0,
                    "inspectErrorNum": 0,
                    "basicErrorNum": 3,
                    "inspectBindNum": 0,
                    "basicBindNum": 1,
                    "reportEpNum": 1*/
//                    当月的计划工作已全部完成
//                    当月工作已完成xx %，剩余xxx污染源
                    circleprogress.setVisibility(View.VISIBLE);
                    circleprogress.reset();
                    circleprogress.clearAnimation();//清除动画试试
                    circleprogress.setValue(dataBean.finishRate * 100); //值
                    //logo下文案
                    if (dataBean.finishRate == 1) {
                        //已完成
                        tvMain1Logo.setText("当前污染源审核工作已全部完成");
                    } else {
                        tvMain1Logo.setText("当月工作已完成" + dataBean.finishRate * 100 + "%\n剩余" + dataBean.remainNum + "污染源");
                    }

                    if (dataBean.basicErrorNum == 0 && dataBean.inspectErrorNum == 0 && dataBean.reportNum == 0) {
                        //没有错误数据
                        circleprogress.setGradientColors(gradientColorsGreen);
                        ivMain1Logo.setImageResource(R.mipmap.ic_shield_green);
                        llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_green);
                        ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_green);
                        ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_green);
                        ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_green);
                        tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_tips));
                        tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_tips));
                        tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_tips));
                        ivMain1JichushujuRight.setVisibility(View.GONE);
                        ivMain1XunchashujuRight.setVisibility(View.GONE);
                        ivMain1YichangjubaoRight.setVisibility(View.GONE);
                        llMain1Jichushuju.setEnabled(false);
                        llMain1Xunchashuju.setEnabled(false);
                        llMain1Yichangjubao.setEnabled(false);
                    } else if (dataBean.basicErrorNum != 0 && dataBean.inspectErrorNum != 0 && dataBean.reportNum != 0) {
                        //全部都有错误数据
                        circleprogress.setGradientColors(gradientColorsRed);
                        ivMain1Logo.setImageResource(R.mipmap.ic_shield_red);
                        llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_red);
                        ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_red);
                        ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_red);
                        ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_red);
                        tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_red));
                        tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_red));
                        tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_red));
                        ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                        ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                        ivMain1YichangjubaoRight.setVisibility(View.VISIBLE);
                        llMain1Jichushuju.setEnabled(true);
                        llMain1Xunchashuju.setEnabled(true);
                        llMain1Yichangjubao.setEnabled(true);
                    } else {
                        //包含错误，但不是全部错误
                        //logo和下面文案
                        circleprogress.setGradientColors(gradientColorsYellow);
                        ivMain1Logo.setImageResource(R.mipmap.ic_shield_yellow);
                        llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_orange);
                        ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_orange);
                        ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_orange);
                        ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_orange);
                        //基础数据
                        if (dataBean.basicErrorNum == 0) {
                            tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_tips));
                            ivMain1JichushujuRight.setVisibility(View.GONE);
                            llMain1Jichushuju.setEnabled(false);
                        } else {
                            tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_orange));
                            ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                            llMain1Jichushuju.setEnabled(true);
                        }
                        //巡查数据文案
                        if (dataBean.inspectErrorNum == 0) {
                            tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_tips));
                            ivMain1XunchashujuRight.setVisibility(View.GONE);
                            llMain1Xunchashuju.setEnabled(false);
                        } else {
                            tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_orange));
                            ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                            llMain1Xunchashuju.setEnabled(true);
                        }
                        //异常举报文案
                        if (dataBean.reportNum == 0) {
                            tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_tips));
                            ivMain1YichangjubaoRight.setVisibility(View.GONE);
                            llMain1Yichangjubao.setEnabled(false);
                        } else {
                            tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_orange));
                            ivMain1YichangjubaoRight.setVisibility(View.VISIBLE);
                            llMain1Yichangjubao.setEnabled(true);
                        }
                    }

                    //基础数据文案
                    tvMain1Jichushuju.setText("待审核" + dataBean.basicBindNum + "家污染源，其中异常" + dataBean.basicErrorNum + "家");
                    //巡查数据文案
                    tvMain1Xunchashuju.setText("待审核" + dataBean.inspectBindNum + "家污染源，其中异常" + dataBean.inspectErrorNum + "家");
                    //异常举报文案
                    tvMain1Yichangjubao.setText(dataBean.reportEpNum + "家污染源举报数据待处理");

                    ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                    ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                    ivMain1YichangjubaoRight.setVisibility(View.VISIBLE);
                    llMain1Jichushuju.setEnabled(true);
                    llMain1Xunchashuju.setEnabled(true);
                    llMain1Yichangjubao.setEnabled(true);
                } else if (Session.getInstance().getUserRole().equals("监督员")) {
                    /*  "finishRate":1.0,
                                "remainNum":0,
                                "reportNum":4,
                                "inspectAuditNum":0,
                                "inspectErrorNum":0
                                "basicErrorNum": 0,
                                 "basicAuditNum": 0*/
//                    当月范围污染源审核工作已全部完成
//                    当月工作已完成xx %，剩余xxx污染源
                    circleprogress.setVisibility(View.VISIBLE);
                    circleprogress.reset();
                    circleprogress.clearAnimation();//清除动画试试
                    circleprogress.setValue(dataBean.finishRate * 100); //值
                    //logo下文案
                    if (dataBean.finishRate == 1) {
                        //已完成
                        tvMain1Logo.setText("当月范围污染源审核工作已全部完成");
                    } else {
                        tvMain1Logo.setText("当月工作已完成" + dataBean.finishRate * 100 + "%\n剩余" + dataBean.remainNum + "污染源");
                    }

                    if (dataBean.basicErrorNum == 0 && dataBean.inspectErrorNum == 0 && dataBean.reportNum == 0) {
                        //没有错误数据
                        circleprogress.setGradientColors(gradientColorsGreen);
                        ivMain1Logo.setImageResource(R.mipmap.ic_shield_green);
                        llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_green);
                        ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_green);
                        ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_green);
                        ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_green);
                        tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_tips));
                        tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_tips));
                        tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_tips));
                        ivMain1JichushujuRight.setVisibility(View.GONE);
                        ivMain1XunchashujuRight.setVisibility(View.GONE);
                        ivMain1YichangjubaoRight.setVisibility(View.GONE);
                        llMain1Jichushuju.setEnabled(false);
                        llMain1Xunchashuju.setEnabled(false);
                        llMain1Yichangjubao.setEnabled(false);
                    } else if (dataBean.basicErrorNum != 0 && dataBean.inspectErrorNum != 0 && dataBean.reportNum != 0) {
                        //全部都有错误数据
                        circleprogress.setGradientColors(gradientColorsRed);
                        ivMain1Logo.setImageResource(R.mipmap.ic_shield_red);
                        llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_red);
                        ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_red);
                        ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_red);
                        ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_red);
                        tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_red));
                        tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_red));
                        tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_red));
                        ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                        ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                        ivMain1YichangjubaoRight.setVisibility(View.VISIBLE);
                        llMain1Jichushuju.setEnabled(true);
                        llMain1Xunchashuju.setEnabled(true);
                        llMain1Yichangjubao.setEnabled(true);
                    } else {
                        //包含错误，但不是全部错误
                        //logo和下面文案
                        circleprogress.setGradientColors(gradientColorsYellow);
                        ivMain1Logo.setImageResource(R.mipmap.ic_shield_yellow);
                        llMain1Bg.setBackgroundResource(R.mipmap.ic_main_bg_orange);
                        ivMain1Jichushuju.setImageResource(R.mipmap.ic_jichushuju_orange);
                        ivMain1Xunchashuju.setImageResource(R.mipmap.ic_xunchashuju_orange);
                        ivMain1Yichangjubao.setImageResource(R.mipmap.ic_yichangshuju_orange);
                        //基础数据
                        if (dataBean.basicErrorNum == 0) {
                            tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_tips));
                            ivMain1JichushujuRight.setVisibility(View.GONE);
                            llMain1Jichushuju.setEnabled(false);
                        } else {
                            tvMain1Jichushuju.setTextColor(getResources().getColor(R.color.common_orange));
                            ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                            llMain1Jichushuju.setEnabled(true);
                        }
                        //巡查数据文案
                        if (dataBean.inspectErrorNum == 0) {
                            tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_tips));
                            ivMain1XunchashujuRight.setVisibility(View.GONE);
                            llMain1Xunchashuju.setEnabled(false);
                        } else {
                            tvMain1Xunchashuju.setTextColor(getResources().getColor(R.color.common_orange));
                            ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                            llMain1Xunchashuju.setEnabled(true);
                        }
                        //异常举报文案
                        if (dataBean.reportNum == 0) {
                            tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_tips));
                            ivMain1YichangjubaoRight.setVisibility(View.GONE);
                            llMain1Yichangjubao.setEnabled(false);
                        } else {
                            tvMain1Yichangjubao.setTextColor(getResources().getColor(R.color.common_orange));
                            ivMain1YichangjubaoRight.setVisibility(View.VISIBLE);
                            llMain1Yichangjubao.setEnabled(true);
                        }
                    }

                    //基础数据文案
                    if (dataBean.basicErrorNum == 0) {
                        tvMain1Jichushuju.setText("当前全部污染源已通过基础审核");
                    } else {
                        tvMain1Jichushuju.setText("待审核" + dataBean.basicAuditNum + "家污染源，其中异常" + dataBean.basicErrorNum + "家");
                    }
                    //巡查数据文案
                    if (dataBean.inspectErrorNum == 0) {
                        tvMain1Xunchashuju.setText("当前全部污染源已通过巡查审核");
                    } else {
                        tvMain1Xunchashuju.setText("待审核" + dataBean.inspectAuditNum + "家污染源，其中异常" + dataBean.inspectErrorNum + "家");
                    }
                    //异常举报文案
                    if (dataBean.reportNum == 0) {
                        tvMain1Yichangjubao.setText("未提交过污染源异常");
                    } else {
                        tvMain1Yichangjubao.setText(dataBean.reportNum + "家污染源举报数据待处理");
                    }

                    ivMain1JichushujuRight.setVisibility(View.VISIBLE);
                    ivMain1XunchashujuRight.setVisibility(View.VISIBLE);
                    ivMain1YichangjubaoRight.setVisibility(View.VISIBLE);
                    llMain1Jichushuju.setEnabled(true);
                    llMain1Xunchashuju.setEnabled(true);
                    llMain1Yichangjubao.setEnabled(true);
                }
            }
        }
    }

    @OnClick({R.id.civ_main_photo, R.id.iv_main_erweima, R.id.iv_main1_logo, R.id.ll_main1_jichushuju, R.id.ll_main1_xunchashuju, R.id.ll_main1_yichangjubao})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.civ_main_photo://头像
                EventBus.getDefault().post(true, "MainActivity.openDrawer");//发出通知给MainActivity，打开左抽屉
                break;
            case R.id.iv_main_erweima://右上角二维码
                JumpHelper.jump(getActivity(), MipcaCaptureActivity.class, false);
                break;
            case R.id.iv_main1_logo://应用logo
                break;
            case R.id.ll_main1_jichushuju://基础数据
                Intent jichushujuIntent = new Intent(getActivity(), TiJianActivity.class);
                jichushujuIntent.putExtra("type", "basic");
                JumpHelper.jump(getActivity(), jichushujuIntent, false);
                break;
            case R.id.ll_main1_xunchashuju://巡查数据
                Intent xunchashujuIntent = new Intent(getActivity(), TiJianActivity.class);
                xunchashujuIntent.putExtra("type", "inspect");
                JumpHelper.jump(getActivity(), xunchashujuIntent, false);
                break;
            case R.id.ll_main1_yichangjubao://异常举报
                Intent yichangjubaoIntent = new Intent(getActivity(), TiJianActivity.class);
                yichangjubaoIntent.putExtra("type", "report");
                JumpHelper.jump(getActivity(), yichangjubaoIntent, false);
                break;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscriber(tag = "MainActivity.refreshFragment")
    private void refreshFragment(boolean flag) {
        LogUtils.e("Main1Fragment receive MainActivity.refreshFragment");
        updateUiByStatus(null);
        indexIndex();
        initData();
    }
}
